﻿using System;
using System.Collections.Generic;
using Godot;

namespace kemocard.Scripts.Card.Scripts;

public static class CardFactory
{
    private static readonly Dictionary<string, Type> CardTypeDict = new()
    {
        { "1", typeof(C1) },
        { "2", typeof(C2) },
        { "3", typeof(C3) },
        { "4", typeof(C4) },
        { "5", typeof(C5) },
        { "6", typeof(C6) },
        { "7", typeof(C7) },
        { "8", typeof(C8) },
        { "9", typeof(C9) },
        { "10", typeof(C10) },
        { "11", typeof(C11) },
        { "12", typeof(C12) },
        { "13", typeof(C13) },
        { "14", typeof(C14) },
        { "15", typeof(C15) },
        { "16", typeof(C16) },
        { "17", typeof(C17) },
        { "18", typeof(C18) },
        { "19", typeof(C19) },
        { "20", typeof(C20) },
        { "21", typeof(C21) },
        { "22", typeof(C22) },
        { "23", typeof(C23) },
        { "24", typeof(C24) },
        { "25", typeof(C25) },
        { "26", typeof(C26) },
        { "27", typeof(C27) },
        { "28", typeof(C28) },
        { "29", typeof(C29) },
        { "30", typeof(C30) },
        { "31", typeof(C31) },
        { "32", typeof(C32) },
        { "33", typeof(C33) },
        { "34", typeof(C34) },
        { "35", typeof(C35) },
        { "36", typeof(C36) },
        { "37", typeof(C37) },
        { "38", typeof(C38) },
        { "39", typeof(C39) },
        { "40", typeof(C40) },
        { "41", typeof(C41) },
        { "42", typeof(C42) },
        { "43", typeof(C43) },
        { "44", typeof(C44) },
        { "45", typeof(C45) },
        { "46", typeof(C46) },
        { "47", typeof(C47) },
        { "48", typeof(C48) },
        { "49", typeof(C49) },
        { "50", typeof(C50) },
        { "51", typeof(C51) },
        { "52", typeof(C52) },
        { "ACID_WORM_ATTACKER", typeof(AcidWormAttacker) },
        { "ACID_WORM_BLOCKER", typeof(AcidWormBlocker) },
        { "ACID_WORM_GUARD", typeof(AcidWormGuard) },
        { "ACID_WORM_SUPPORT", typeof(AcidWormSupport) },
        { "BAT_EARTH_ATTACK", typeof(BatEarthAttack) },
        { "BAT_EARTH_GUARD", typeof(BatEarthGuard) },
        { "BAT_EARTH_BLOCKER", typeof(BatEarthBlocker) },
        { "BAT_EARTH_SUPPORT", typeof(BatEarthSupport) },
        { "ROVER_TYPHOON_ATTACKER", typeof(RoverTyphoonAttacker) },
        { "ROVER_TYPHOON_GUARD", typeof(RoverTyphoonGuard) },
        { "ROVER_TYPHOON_SUPPORT", typeof(RoverTyphoonSupport) },
        { "ROVER_TYPHOON_BLOCKER", typeof(RoverTyphoonBlocker) },
        { "SN_STAR_ATTACKER", typeof(SnStarAttacker) },
        { "SN_STAR_GUARD", typeof(SnStarGuard) },
        { "SN_STAR_SUPPORT", typeof(SnStarSupport) },
        { "SN_STAR_BLOCKER", typeof(SnStarBlocker) },
        { "FES_ZELLER_ATTACKER", typeof(FesZellerAttacker) },
        { "FES_ZELLER_GUARD", typeof(FesZellerGuard) },
        { "FES_ZELLER_SUPPORT", typeof(FesZellerSupport) },
        { "FES_ZELLER_BLOCKER", typeof(FesZellerBlocker) },
        { "SN_SETH_ATTACKER", typeof(SnSethAttacker) },
        { "SN_SETH_GUARD", typeof(SnSethGuard) },
        { "SN_SETH_SUPPORT", typeof(SnSethSupport) },
        { "SN_SETH_BLOCKER", typeof(SnSethBlocker) },
        { "53", typeof(C53) },
        { "54", typeof(C54) },
        { "55", typeof(C55) },
        { "56", typeof(C56) },
        { "57", typeof(C57) },
        { "58", typeof(C58) },
        { "59", typeof(C59) },
        { "60", typeof(C60) },
        { "61", typeof(C61) },
        { "62", typeof(C62) },
        { "63", typeof(C63) },
        { "64", typeof(C64) },
        { "65", typeof(C65) },
        { "66", typeof(C66) },
        { "67", typeof(C67) },
        { "68", typeof(C68) },
        { "SLIME_EARTH_ATTACKER", typeof(SlimeEarthAttacker) },
        { "SLIME_EARTH_GUARD", typeof(SlimeEarthGuard) },
        { "SLIME_EARTH_SUPPORT", typeof(SlimeEarthSupport) },
        { "SLIME_EARTH_BLOCKER", typeof(SlimeEarthBlocker) },
        { "SWAN_ATTACKER", typeof(SwanAttacker) },
        { "SWAN_GUARD", typeof(SwanGuard) },
        { "SWAN_SUPPORT", typeof(SwanSupport) },
        { "SWAN_BLOCKER", typeof(SwanBlocker) },
        { "LIZ_EARTH_ATTACKER", typeof(LizEarthAttacker) },
        { "LIZ_EARTH_GUARD", typeof(LizEarthGuard) },
        { "LIZ_EARTH_SUPPORT", typeof(LizEarthSupport) },
        { "LIZ_EARTH_BLOCKER", typeof(LizEarthBlocker) },
        { "SCI_SANTOS_A", typeof(SciSantosA) },
        { "SCI_SANTOS_B", typeof(SciSantosB) },
        { "SCI_SANTOS_G", typeof(SciSantosG) },
        { "SCI_SANTOS_S", typeof(SciSantosS) },
        { "SS_RAINS_A", typeof(SsRainsA) },
        { "SS_RAINS_B", typeof(SsRainsB) },
        { "SS_RAINS_G", typeof(SsRainsG) },
        { "SS_RAINS_S", typeof(SsRainsS) },
        { "FORTIS_CARTER_A", typeof(FortisCarterA) },
        { "FORTIS_CARTER_B", typeof(FortisCarterB) },
        { "FORTIS_CARTER_G", typeof(FortisCarterG) },
        { "FORTIS_CARTER_S", typeof(FortisCarterS) },
        { "KNIGHT_COLLIN_A", typeof(KnightCollinA) },
        { "KNIGHT_COLLIN_G", typeof(KnightCollinG) },
        { "KNIGHT_COLLIN_B", typeof(KnightCollinB) },
        { "KNIGHT_COLLIN_S", typeof(KnightCollinS) },
        { "FORTIS_ZELLER_A", typeof(FortisZellerA) },
        { "FORTIS_ZELLER_G", typeof(FortisZellerG) },
        { "FORTIS_ZELLER_B", typeof(FortisZellerB) },
        { "FORTIS_ZELLER_S", typeof(FortisZellerS) },
        { "KNIGHT_FORGE_A", typeof(KnightForgeA) },
        { "KNIGHT_FORGE_G", typeof(KnightForgeG) },
        { "KNIGHT_FORGE_B", typeof(KnightForgeB) },
        { "KNIGHT_FORGE_S", typeof(KnightForgeS) },
        { "FLOWER_MERLIN_A", typeof(FlowerMerlinA) },
        { "FLOWER_MERLIN_G", typeof(FlowerMerlinG) },
        { "FLOWER_MERLIN_B", typeof(FlowerMerlinB) },
        { "FLOWER_MERLIN_S", typeof(FlowerMerlinS) },
        { "VALENTINE_SS_A", typeof(ValentineSsA) },
        { "VALENTINE_SS_B", typeof(ValentineSsB) },
        { "VALENTINE_SS_G", typeof(ValentineSsG) },
        { "VALENTINE_SS_S", typeof(ValentineSsS) },
        { "METAL_ZC_A", typeof(MetalZcA) },
        { "METAL_ZC_G", typeof(MetalZcG) },
        { "METAL_ZC_B", typeof(MetalZcB) },
        { "METAL_ZC_S", typeof(MetalZcS) },
        { "SCI_RAINS_A", typeof(SciRainsA) },
        { "SCI_RAINS_B", typeof(SciRainsB) },
        { "SCI_RAINS_G", typeof(SciRainsG) },
        { "SCI_RAINS_S", typeof(SciRainsS) },
        { "BALLAD_TYPHOON_A", typeof(BalladTyphoonA) },
        { "BALLAD_TYPHOON_G", typeof(BalladTyphoonG) },
        { "BALLAD_TYPHOON_B", typeof(BalladTyphoonB) },
        { "BALLAD_TYPHOON_S", typeof(BalladTyphoonS) },
        { "OCCULTISM_T_A", typeof(OccultismTripleA) },
        { "OCCULTISM_T_G", typeof(OccultismTripleG) },
        { "OCCULTISM_T_B", typeof(OccultismTripleB) },
        { "OCCULTISM_T_S", typeof(OccultismTripleS) },
        { "CHIVALRY_FC_A", typeof(ChivalryFcA) },
        { "CHIVALRY_FC_G", typeof(ChivalryFcG) },
        { "CHIVALRY_FC_B", typeof(ChivalryFcB) },
        { "CHIVALRY_FC_S", typeof(ChivalryFcS) },
        { "WAITER_COLLIN_A", typeof(WaiterCollinA) },
        { "WAITER_COLLIN_G", typeof(WaiterCollinG) },
        { "WAITER_COLLIN_B", typeof(WaiterCollinB) },
        { "WAITER_COLLIN_S", typeof(WaiterCollinS) },
        { "JAM_RZ_A", typeof(JamRzA) },
        { "JAM_RZ_G", typeof(JamRzG) },
        { "JAM_RZ_B", typeof(JamRzB) },
        { "JAM_RZ_S", typeof(JamRzS) },
        { "SWORD_COLLIN_A", typeof(SwordCollinA) },
        { "SWORD_COLLIN_G", typeof(SwordCollinG) },
        { "SWORD_COLLIN_B", typeof(SwordCollinB) },
        { "SWORD_COLLIN_S", typeof(SwordCollinS) },
        { "SWORD_RAINS_A", typeof(SwordRainsA) },
        { "SWORD_RAINS_G", typeof(SwordRainsG) },
        { "SWORD_RAINS_B", typeof(SwordRainsB) },
        { "SWORD_RAINS_S", typeof(SwordRainsS) },
        { "ONSEN_TYPHOON_A", typeof(OnsenTyphoonA) },
        { "ONSEN_TYPHOON_G", typeof(OnsenTyphoonG) },
        { "ONSEN_TYPHOON_B", typeof(OnsenTyphoonB) },
        { "ONSEN_TYPHOON_S", typeof(OnsenTyphoonS) },
        { "ONSEN_SETH_A", typeof(OnsenSethA) },
        { "ONSEN_SETH_G", typeof(OnsenSethG) },
        { "ONSEN_SETH_B", typeof(OnsenSethB) },
        { "ONSEN_SETH_S", typeof(OnsenSethS) },
        { "ONSEN_STAR_A", typeof(OnsenStarA) },
        { "ONSEN_STAR_G", typeof(OnsenStarG) },
        { "ONSEN_STAR_B", typeof(OnsenStarB) },
        { "ONSEN_STAR_S", typeof(OnsenStarS) },
        { "ONSEN_RAINS_A", typeof(OnsenRainsA) },
        { "ONSEN_RAINS_G", typeof(OnsenRainsG) },
        { "ONSEN_RAINS_B", typeof(OnsenRainsB) },
        { "ONSEN_RAINS_S", typeof(OnsenRainsS) },
        { "ALLEGORY_TP_A", typeof(AllegoryTpA) },
        { "ALLEGORY_TP_G", typeof(AllegoryTpG) },
        { "ALLEGORY_TP_B", typeof(AllegoryTpB) },
        { "ALLEGORY_TP_S", typeof(AllegoryTpS) },
        { "ALLEGORY_SETH_A", typeof(AllegorySethA) },
        { "ALLEGORY_SETH_G", typeof(AllegorySethG) },
        { "ALLEGORY_SETH_B", typeof(AllegorySethB) },
        { "ALLEGORY_SETH_S", typeof(AllegorySethS) },
        { "HALLOWEEN_ELLIS_A", typeof(HalloweenEllisA) },
        { "HALLOWEEN_ELLIS_G", typeof(HalloweenEllisG) },
        { "HALLOWEEN_ELLIS_B", typeof(HalloweenEllisB) },
        { "HALLOWEEN_ELLIS_S", typeof(HalloweenEllisS) },
    };

    /// <summary>
    /// 注册卡，需继承BaseCardScript，重复注册会覆盖
    /// </summary>
    /// <param name="cardId">Id</param>
    /// <param name="cardType">类</param>
    public static void RegisterCard(string cardId, Type cardType)
    {
        if (cardType.IsSubclassOf(typeof(BaseCardScript)) || cardType == typeof(BaseCardScript))
            CardTypeDict[cardId] = cardType;
    }

    public static BaseCardScript CreateCardScript(string id)
    {
        if (CardTypeDict.TryGetValue(id, out var type))
        {
            return Activator.CreateInstance(type) as BaseCardScript;
        }

        GD.PrintErr($"无法找到卡牌, ID:{id}");
        return null;
    }
}